import sys

import pygame
from pyglet.gl import glBegin, glEnd
from OpenGL.GL import *
from OpenGL.GLU import *

faces = (
    (1, -1, -1),
    (1, 1, -1),
    (-1, 1, -1),
    (-1, -1, -1),
    (1, -1, 1),
    (1, 1, 1),
    (-1, -1, 1),
    (-1, 1, 1)
)

lines = (
    (0, 1),
    (0, 3),
    (0, 4),
    (2, 1),
    (2, 3),
    (2, 7),
    (6, 3),
    (6, 4),
    (6, 7),
    (5, 1),
    (5, 4),
    (5, 7)
)


def create_cube():
    glBegin(GL_QUADS)

    glVertex3f(0, 0.5, 0)
    glVertex3f(0.5, 1, 0)
    glVertex3f(1, 0.5, 0)
    glVertex3f(0.5, 0, 0)

    glVertex3f(0, 0.5, 0)
    glVertex3f(0.5, 1, 0)
    glVertex3f(1, 0.5, 0)
    glVertex3f(0.5, 0, 0)

    glVertex3f(0, 0, 0)
    glVertex3f(0, 0.25, 0)
    glVertex3f(0.25, 0.25, 0)
    glVertex3f(0.25, 0, 0)

    glEnd()


if __name__ == '__main__':
    win_size = 600, 600
    pygame.init()
    diaplay = pygame.display.set_mode(win_size, pygame.DOUBLEBUF | pygame.OPENGL)

    gluPerspective(45, (win_size[0] / win_size[1]), 0.1, 50)
    glTranslatef(0.0, 0.0, -5)
    glRotate(0, 0, 0, 0)

    while True:
        for event in pygame.event.get():
            if event.type is pygame.QUIT:
                sys.exit()
            if event.type is pygame.KEYDOWN:
                if event.key is pygame.K_ESCAPE:
                    pygame.quit()
                    quit()

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        create_cube()
        pygame.display.flip()
